package edu.polsl.bio.tools.str;

import edu.polsl.bio.tools.util.Utils;

import java.io.Serializable;

/**
 * //todo class description
 * <p/>
 * Created on: Jun 11, 2011 4:34:23 PM <br/>
 * <a href="http://www.polsl.pl">www.polsl.pl</a>
 *
 * @author lukasz.olczak@polsl.pl
 */
public class StrRecord implements Serializable {
  private long id;

  private String motif;

  private int startIndex;

  private int endIndex;

  private int noRepeats;

  private int motifLength;

  private double ratio;

  private String leftFlank;

  private String rightFlank;

  public StrRecord(String motif, int start, int end) {
    this.motif = motif;
    this.startIndex = start;
    this.endIndex = end;
    this.motifLength = motif.length();
    this.ratio = (double) (endIndex - startIndex + 1) / (double) motifLength;
    this.noRepeats = (int) Math.floor(ratio);
  }

  public StrRecord(String motif, int start, int end, double ratio) {
    this.motif = motif;
    this.startIndex = start;
    this.endIndex = end;
    this.ratio = ratio;
    this.noRepeats = (int) Math.floor(ratio);
    this.motifLength = motif.length();
  }

  public StrRecord getReverseStr() {
    StrRecord reverse = new StrRecord(Utils.reverseDna(motif), startIndex, endIndex);
    reverse.setLeftFlank(Utils.reverseDna(this.getRightFlank()));
    reverse.setRightFlank(Utils.reverseDna(this.getLeftFlank()));
    reverse.setId(this.id);
    return reverse;
  }

  public long getId() {
    return id;
  }

  public void setId(long id) {
    this.id = id;
  }

  public String getMotif() {
    return motif;
  }

  public int getStartIndex() {
    return startIndex;
  }

  public int getNoRepeats() {
    return noRepeats;
  }

  public int getEndIndex() {
    return endIndex;
  }

  public int getMotifLength() {
    return motifLength;
  }

  public double getRatio() {
    return ratio;
  }

  public int getLength() {
    return endIndex - startIndex + 1;
  }

  public String getLeftFlank() {
    return leftFlank;
  }

  public void setLeftFlank(String leftFlank) {
    this.leftFlank = leftFlank.toUpperCase();
  }

  public String getRightFlank() {
    return rightFlank;
  }

  public void setRightFlank(String rightFlank) {
    this.rightFlank = rightFlank.toUpperCase();
  }

  @Override
  public String toString() {
    return "StrRecord{" +
           "motif='" + motif + '\'' +
           ", startIndex=" + startIndex +
           ", endIndex=" + endIndex +
           ", noRepeats=" + noRepeats +
           ", motifLength=" + motifLength +
           ", ratio=" + ratio +
           ", leftFlank='" + leftFlank + '\'' +
           ", rightFlank='" + rightFlank + '\'' +
           '}';
  }
}
